# 通用函数

def load_class(class_path, class_name, request):
    # try:
    # 加载模块
    pkg_main = __import__(class_path)
    # 迭代加载对应的class
    split_pkg = class_path.split('.')[1:]
    for p in split_pkg:
        pkg_main = getattr(pkg_main, p)
    pkg_main = getattr(pkg_main, class_name)
    get_class = pkg_main(request)
    return get_class
    # except Exception as e:
    #     print(e)
    #     return None


def load_class_with_args(class_path, class_name, request, *args, **kwargs):
    # try:
    # 加载模块
    pkg_main = __import__(class_path)
    # 迭代加载对应的class
    split_pkg = class_path.split('.')[1:]
    for p in split_pkg:
        pkg_main = getattr(pkg_main, p)
    pkg_main = getattr(pkg_main, class_name)
    get_class = pkg_main(request, args, kwargs)
    return get_class
    # except Exception as e:
    #     print(e)
    #     return None
